package main

import (
	"fmt"
	"strings"
)

//练习：归类 字符串中单词的个数。
func main() {
	str := "i love my country, family, i  love  Q"

	slice := strings.Fields(str) //将字符串分割成切片
	m := make(map[string]int, 10)

	//遍历切片
	for _, v := range slice {
		if _, have := m[v]; have {
			m[v]++
		} else {
			m[v] = 1
		}
	}

	for k, v := range m {
		fmt.Printf("%s 出现了 %d 次\n", k, v)
	}
}
